<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">

  </div>
</template>

<script>
// @ is an alias to /src
// 拦截器：在请求或响应被处理前拦截它们
// 请求拦截器，响应拦截器

import axios from 'axios'
import { prototype } from 'mini-css-extract-plugin';
import { promised } from 'q';
import { promises } from 'dns';

export default {
  name: 'axios3-3',
  components: {

  },
  created () {
    axios.interceptors.request.use(config => {
      //请求前做些什么
      return config
    }, err => {
      //在请求错误的时候做些什么
      return Promise.reject(err)
    })
    //响应拦截器
    axios.interceptors.request.ues(res => {
      //请求成功响应数据做处理
      return res
    }, err => {
      //响应错误做些什么
      return Promise.reject(err)
    })
    axios.get().then(res => {

    })
    axios, get().then().catch(err => {

    })
    //取消拦截器（了解）
    let interceptors =
      axios.interceptors.request.ues(config => {
        config.headers = {
          auth: ture
        }
        return config
      })
    axios.interceptors.request.eject(interceptors)
    //例子 登陆状态(token:'')需要登陆的接口
    let instance = axios.create({})
    instance.interceptors.request.ues(config => {
      config.headers.token = ''
      return config
    })
    // 不需要登陆的接口
    let newInstance = axios.create({})
    //移动端开发
    let instance_phone = axios.create({})
    instance_phone.interceptors.request.use(config => {
      $('model').show()
      return config
    })
    instance_phone.interceptors.response.use(res => {
      $('model').hide()
      return res
    })
  },
}
</script>
